<!DOCTYPE html>
<html th:lang="${#locale.language}" th:dir="#{language.direction}" th:data-language="${#locale.toString()}"
  xmlns:th="https://www.thymeleaf.org">

<head>
  <th:block th:insert="~{fragments/common :: head(title=#{editTableOfContents.title}, header=#{editTableOfContents.header})}">
  </th:block>
  <link rel="stylesheet" th:href="@{'/css/edit-table-of-contents.css'}">
</head>

<body>
  <div id="page-container">
    <div id="content-wrap">
      <th:block th:insert="~{fragments/navbar.html :: navbar}"></th:block>
      <br><br>
      <div class="container">
        <div class="row justify-content-center">
          <div class="col-md-8 bg-card">
            <div class="tool-header">
              <span class="material-symbols-rounded tool-header-icon edit">bookmark_add</span>
              <span class="tool-header-text" th:text="#{editTableOfContents.header}"></span>
            </div>
            <form th:action="@{'/api/v1/general/edit-table-of-contents'}" method="post" enctype="multipart/form-data" id="editTocForm">
              <div
                th:replace="~{fragments/common :: fileSelector(name='fileInput', multipleInputsForSingleRequest=false, accept='application/pdf')}">
              </div>

              <div class="mb-3 form-check">
                <input type="checkbox" class="form-check-input" id="replaceExisting" name="replaceExisting" checked>
                <label class="form-check-label" for="replaceExisting"
                  th:text="#{editTableOfContents.replaceExisting}"></label>
                <input type="hidden" name="replaceExisting" value="false" />
              </div>

              <div class="bookmark-editor">
                <h5 th:text="#{editTableOfContents.editorTitle}"></h5>
                <p th:text="#{editTableOfContents.editorDesc}"></p>
                
                <div id="bookmarks-container">
                  <!-- Bookmarks will be added here dynamically -->
                </div>
                
                <div class="bookmark-actions">
                  <button type="button" id="addBookmarkBtn" class="btn btn-outline-primary" th:text="#{editTableOfContents.addBookmark}"></button>
                </div>
                
                <!-- Hidden field to store JSON data -->
                <input type="hidden" id="bookmarkData" name="bookmarkData" value="[]">
              </div>

              <p>
                <a class="btn btn-outline-primary" data-bs-toggle="collapse" href="#info" role="button"
                  aria-expanded="false" aria-controls="info" th:text="#{info}"></a>
              </p>
              <div class="collapse" id="info">
                <p th:text="#{editTableOfContents.desc.1}"></p>
                <p th:text="#{editTableOfContents.desc.2}"></p>
                <p th:text="#{editTableOfContents.desc.3}"></p>
              </div>

              <br>
              <button type="submit" id="submitBtn" class="btn btn-primary" th:text="#{editTableOfContents.submit}"></button>
            </form>
          </div>
        </div>
      </div>
    </div>
    <th:block th:insert="~{fragments/footer.html :: footer}"></th:block>
  </div>

  <script th:src="@{'/js/pages/edit-table-of-contents.js'}"></script>
  <script>
    document.addEventListener('DOMContentLoaded', function() {
      // Initialize Bootstrap tooltips
      if (typeof $ !== 'undefined') {
        $('[data-bs-toggle="tooltip"]').tooltip();
      }
    });
  </script>
</body>

</html>